﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XsqTech.SmartOA.Domain.Table;
using XsqTech.SmartOA.Dtos.DTO.Dict;
using XsqTech.SmartOA.IService;

namespace XsqTech.SmartOA.Application.Controllers
{
    /// <summary>
    /// 字典从表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class DictDetailsController : ControllerBase
    {
        public IDictDetailsService _jie;

        public DictDetailsController(IDictDetailsService jie)
        {
            _jie = jie;
        }
        /// <summary>
        /// 数据字典从表显示
        /// </summary>
        /// <param name="name"></param>
        /// <param name="size"></param>
        /// <param name="dang"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("dictdetailsshow")]
        public IActionResult DictDetailsShow(string name, int id = 0, int size = 3, int dang = 1)
        {
            var list = _jie.DictDetailsShow(name, id, size, dang);
            var count = list.Count;
            list = list = list.OrderBy(x => x.DetailsId).Skip((dang - 1) * size).Take(size).ToList();
            return Ok(new { data = list, count = count });
        }
        /// <summary>
        /// 数据字典从表添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("dictdetailsadd")]
        public IActionResult DictDetailsAdd(DictDetails model)
        {
            model.DetailsCreateUser = "abmin";
            model.DetailsUpdateUser = "abmin";
            return Ok(new { va = _jie.DictDetailsAdd(model) });
        }
        /// <summary>
        /// 数据字典从表修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("dictdetailsupdate")]
        public IActionResult DictDetailsUpdate(DictDetailsUpdateDTO model)
        {
            model.DetailsUpdateUser = "abmin";
            var shu = _jie.DictDetailsUpdate(model);
            return Ok(new { tt = "操作成功" });
        }
        /// <summary>
        /// 数据字典从表删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("dictdetailsdelete")]
        public IActionResult DictDetailsDelete(int id)
        {
            return Ok(new { ll = _jie.DetailsDelete(id) });
        }
        /// <summary>
        /// 数据字典从表反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("dictrefill")]
        public DictDetails DictRefill(int id)
        {
            return _jie.DictRefill(id);
        }
    }
}